package states.gameplay.shapors;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;

public class EnemyCreep extends Shapor {
	private static Color COLOR_LEVEL_1 = new Color(152, 205, 249);
	private static Color COLOR_LEVEL_2 = new Color(130, 175, 213);
	private static Color COLOR_LEVEL_3 = new Color(93, 126, 154);
	private static Color COLOR_LEVEL_4 = new Color(65, 89, 109);
	private static Color COLOR_LEVEL_5 = new Color(34, 53, 68);

	private Image _render;
	
	private int _level;
	private int _time;
	private Color _currentColor;
	
	public EnemyCreep(Image render){
		super(1, 0, 0, 0, 0);
		
		_render = render;
		
		_level = 1;
		updateColor();
	}
	
	public EnemyCreep(int deployLimits, int cost, int deployPulses,
			int energyGenerated, int energyUpkeep) {
		super(deployLimits, cost, deployPulses, energyGenerated, energyUpkeep);
	}

	@Override
	public void render(Graphics g, int x, int y) {
		_render.draw(x - (_render.getWidth())/2, y - (_render.getHeight())/2, 20, 20, _currentColor);
		
		//g.drawString(""+_level, x - (_render.getWidth())/2, y - (_render.getHeight())/2);
	}

	public int getLevel() {
		return _level;
	}

	public void setLevel(int level) {
		this._level = level;
		if(_level < 0){
			_level = 0;
		}
		if(_level > 5){
			_level = 5;
		}
		updateColor();
	}
	
	public void removeLevel(int amount){
		setLevel(_level - amount);
	}
	
	public void addLevel(int amount){
		setLevel(_level + amount);
	}

		
	private void updateColor() {
		
		switch (_level) {
		case 1:
			_currentColor = COLOR_LEVEL_1;
			break;
		case 2:
			_currentColor = COLOR_LEVEL_2;
			break;
		case 3:
			_currentColor = COLOR_LEVEL_3;
			break;
		case 4:
			_currentColor = COLOR_LEVEL_4;
			break;
		case 5:
			_currentColor = COLOR_LEVEL_5;
			break;
		default:
			break;
		}
	}

	
	public int getTime() {
		return _time;
	}

	public void update(int time) {
		_time += time;
		
		if(_time > 10000*_level){
			if(_level < 5){
				addLevel(1);
				_time = 0;
			}
		}
	}

}
